<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html {
            height: 100%;
        }

        body {
            display: flex;
            justify-content: center;
            height: 100%;
            align-items: center;
        }

        img {
            width: 800px;
            display: none;
        }

        .on {
            display: block;
        }

        div {
            width: 800px;
        }
    </style>
</head>

<body>
    <div><img class="on" src="./img/01.png" alt="">
        <img src="./img/02.png" alt="">
        <img src="./img/03.png" alt="">
        <img src="./img/04.png" alt="">
        <img src="./img/05.png" alt="">
        <img src="./img/06.png" alt="">
        <img src="./img/07.png" alt="">
        <img src="./img/08.png" alt="">
    </div>

    <script>
        let src = document.querySelectorAll("img")
        let div = document.querySelector("div")

        // 定义一个变量用来记录相片的下标
        let x = 0
        console.log(src);
        setInterval(function () {
            src[x].className = "on"
            if (x == 0) {
                src[src.length - 1].className = ""
            }
            if (x > 0) {
                src[x - 1].className = ""
            }
            x++
            if (x > src.length - 1) {
                x = 0
            }
        }, 1500)


    </script>

</body>

</html>